package net.guerlab.sdk.anubis.helper;

import java.net.URLDecoder;
import java.net.URLEncoder;

import net.guerlab.sdk.anubis.AnubisConstants;
import net.guerlab.sdk.anubis.AnubisException;

/**
 * URL编码解码助手
 * 
 * @author guer
 *
 */
public class URLHelper {

    private URLHelper() {
    }

    /**
     * 编码
     * 
     * @param source
     *            原内容
     * @return 编码内容
     */
    public static String encode(
            String source) {
        try {
            return URLEncoder.encode(source, AnubisConstants.CHARSET_UTF8);
        } catch (Exception e) {
            throw new AnubisException(e.getMessage(), e);
        }
    }

    /**
     * 解码
     * 
     * @param source
     *            原内容
     * @return 解码内容
     */
    public static String decode(
            String source) {
        try {
            return URLDecoder.decode(source, AnubisConstants.CHARSET_UTF8);
        } catch (Exception e) {
            throw new AnubisException(e.getMessage(), e);
        }
    }
}
